<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基金产品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/common/constant.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

         <fieldset class="table-search-fieldset">
             <legend>搜索信息</legend>
             <div style="margin: 10px 10px 10px 10px">
                 <form class="layui-form layui-form-pane" action="">
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label">基金代码</label>
                             <div class="layui-input-inline">
                                 <input type="text" name="fundNumber" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">基金名称</label>
                             <div class="layui-input-inline">
                                 <input type="text" name="fundName" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">基金类型</label>
                             <div class="layui-input-inline">
                                 <select id="fundType" name="fundType" value="" class="layui-input">
                                     <option value="">请选择</option>
                                     <option value="1">混合型</option>
                                     <option value="2">股票型</option>
                                     <option value="3">债券型</option>
                                     <option value="4">指数型</option>
                                     <option value="5">FOF型</option>
                                     <option value="6">QDII型</option>
                                 </select>
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">风险等级</label>
                             <div class="layui-input-inline">
                                <select id="raskRating" name="raskRating" value="" class="layui-input">
                                    <option value="">请选择</option>
                                    <option value="1">R1</option>
                                    <option value="2">R2</option>
                                    <option value="3">R3</option>
                                    <option value="4">R4</option>
                                    <option value="5">R5</option>
                                </select>
                             </div>
                         </div>
                         <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                               <select id="state" name="state" value="" class="layui-input">
                                   <option value="">请选择</option>
                                   <option value="0">已上线</option>
                                   <option value="1">已下架</option>
                               </select>
                            </div>
                        </div>
                         <div class="layui-inline">
                             <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                         </div>
                     </div>
                 </form>
             </div>
         </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">新增基金</button>
                <!-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button> -->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">

            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="fundRecord"">基金档案</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="cost">运作费用</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-add" lay-event="soldUp">上架</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="soldOut">下架</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        </script>

    </div>
</div>
<script>
    layui.use(['form', 'table','layer','laydate'], function () {
        var laydate = layui.laydate;
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            table = layui.table;

        //日期选择
        //常规用法
        laydate.render({
            elem: '#test1'
        });

        table.render({
            elem: '#currentTableId',
            url: getRootPath()+'web/fundinfo/list',
            response:{
                statusCode: 200
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'fundNumber', width: 100, title: '基金代码'},
                {field: 'fundName', width: 100, title: '基金名称'},
                {field: 'fundAbbrevation', width: 100, title: '基金缩写'},
                {field: 'fundType', width: 100, title: '基金类型',templet:function(d){
                    if(d.fundType == 1){
                        return "混合型"
                    }else if(d.fundType == 2){
                        return "股票型"
                    }else if(d.fundType == 3){
                        return "债券型"
                    }else if(d.fundType == 4){
                        return "指数型"
                    }else if(d.fundType == 5){
                        return "FOF型"
                    }else if(d.fundType == 6){
                        return "QDII型"
                    }
                }},
                {field: 'raskRating', width: 110, title: '风险等级',templet:function(d){
                    if(d.raskRating == 1){
                        return "R1"
                    }else if(d.raskRating == 2){
                        return "R2"
                    }else if(d.raskRating == 3){
                        return "R3"
                    }else if(d.raskRating == 4){
                        return "R4"
                    }else if(d.raskRating == 5){
                        return "R5"
                    }
                }},
                {field: 'createTime', width: 160, title: '录入时间'},
                {field: 'updateTime', title: '修改时间', width: 160},
                {field: 'state', width: 80, title: '状态',templet:function(d){
                    if(d.state == 0){
                        return "已上线";
                    }else{
                        return "已下架";
                    }
                }},
                {title: '操作', minWidth: 250, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 5,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    fundNumber: data.field.fundNumber,
                    fundName: data.field.fundName,
                    fundType: data.field.fundType,
                    raskRating: data.field.raskRating,
                    state: data.field.state
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {

            if (obj.event === 'add') {  // 监听添加操作
               var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/page/product/fund-product-add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'soldUp') {
                if(data.state == 1){
                    $.ajax({
                        url:getRootPath()+'web/fundinfo/update-state',
                        type:"PUT",
                        data:{
                            id:data.id,
                            type: "up"
                        },
                        dataType:"json",
                        success:function(data){
                            var index = layer.alert(data.message, {
                                title: '提示信息',
                            },function () {
                                // 关闭弹出层
                                layer.close(index);
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                if(data.code == 200){
                                    window.location.reload();
                                }
                            })
                        }
                    })
                }else {
                    layer.alert("已上线，不能重复操作！")
                }               
            } else if (obj.event === 'soldOut') {
                if(data.state == 0){
                    layer.confirm('真的下架么', function (index) {
                    layer.close(index);
                    $.ajax({
                        url:getRootPath()+'web/fundinfo/update-state',
                        type:"PUT",
                        data:{
                            id:data.id,
                            type: "out"
                        },
                        dataType:"json",
                        success:function(data){
                            var index = layer.alert(data.message, {
                                title: '提示信息',
                            },function () {
                                // 关闭弹出层
                                layer.close(index);
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                if(data.code == 200){
                                    window.location.reload();
                                }
                            })
                        }
                    }) 
                });
                }else{
                    layer.alert("已下架，不能重复操作！")
                }   
            } else if(obj.event === 'fundRecord'){
                var index = layer.open({
                    title: '基金档案信息',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['60%', '85%'],
                    content: '/page/product/fundArchive.html?fundArchiveId=' + data.fundArchiveId,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });

            }else if(obj.event === 'cost'){
                var index = layer.open({
                    title: '基金运作费用',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/page/product/serverCost.html?serverCostId=' + data.serverCostId,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if(obj.event === 'edit'){
                var index = layer.open({
                    title: '基金基础信息修改',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['60%', '85%'],
                    content: '/page/product/fundInfoEdit.html?id=' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

    });
</script>

</body>
</html>